package org.skipper.samples.dubbo.provider.impl;

import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.rpc.RpcContext;
import org.skipper.common.result.RpcResult;
import org.skipper.samples.client.DemoService;
import org.skipper.samples.dto.DemoDTO;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author shoujian
 * Date: 2021-08-09
 * Time: 下午7:20
 */
@Component
@DubboService(version = "1.0.0")
public class DemoServiceImpl implements DemoService {
    @Override
    public RpcResult<DemoDTO> sayHello() {
        DemoDTO demoDTO = new DemoDTO();
        demoDTO.setId(1);
        demoDTO.setName("小明");

        String trafficSources = RpcContext.getContext().getAttachment("trafficSources");
        String dubboTag = RpcContext.getContext().getAttachment("dubbo.tag");
        System.out.println("dubboTag = "+dubboTag);
        if (StringUtils.isEmpty(trafficSources)) {
            demoDTO.setSay("这是个普通发言");
        } else {
            demoDTO.setSay("流量来源已指定：" + trafficSources);
        }

        return RpcResult.createSuccessMsg(demoDTO);
    }
}
